package handler

import (
	"context"
	"kuangstudy-mall/srvs/goods-srv/global"
	"kuangstudy-mall/srvs/goods-srv/model"
	"kuangstudy-mall/srvs/goods-srv/proto"
)

func (h *GoodsServiceHandler) FindBannerList(ctx context.Context, req *proto.BannerInfoRequest) (*proto.BannerListResponse, error) {
	var bannerList []model.Banner
	global.DB.Where("s_type = ? and status = 1", req.Stype).Order("sorted").Find(&bannerList)

	var response proto.BannerListResponse
	response.Total = int32(len(bannerList))

	var dataList []*proto.BannerResponse
	for _, banner := range bannerList {
		dataList = append(dataList, &proto.BannerResponse{
			Id:  banner.ID,
			Img: banner.Img,
			Url: banner.Url,
		})
	}
	response.Data = dataList
	// gorm查询轮播
	return &response, nil
}
